package com.summer.exception;

import java.util.HashMap;


public class ExceptionResolver {
	private  static final HashMap<Class<? extends Exception>,ExceptionHandle> handleMap = new HashMap<>();
	
	//观察者
	
	private static ExceptionHandle defHandle = new ExceptionHandle(){

		@Override
		public void doHandle(Exception ex) {
			System.out.println(ex.getClass().toString());
		}
		
	};
	
	static{
		handleMap.put(NetworkAccessException.class, defHandle);
		handleMap.put(DataAcquisitionException.class, defHandle);
		handleMap.put(DataParsingException.class, defHandle);
	}
	
	public static void handle(Exception ex){
		ExceptionHandle handle = handleMap.get(ex.getClass());
		if(null != handle)
			handle.doHandle(ex);
		else
			ex.printStackTrace();
		//TODO:上报服务器异常
	}
	
	public interface ExceptionHandle{
		void doHandle(Exception ex);
	}
	
	
	
}
